<script setup>
import FirstTitle from "@comp/FirstTitle";
import { postTableData } from "@/api/table";
import { onMounted } from "vue";
import { searchDataZymb } from "@/api/search";
import { addOrUpdateZymb } from "@/api/addOrUpdate";
import { Editor, Toolbar } from "@wangeditor/editor-for-vue";

const city = window.globalObj.name;
const editorRef11 = shallowRef();
const valueHtml11 =
  ref(`1.任务需求：按照有关要求，每个重要目标单位都应部署适当人数的抢险抢修、消防救援、交通运输、通信保障、信息防护、伪装防护等人防专业队。
2.能力现状：重要目标单位负责组建的专业队共有12支，其中：*****组建了重要目标抢险抢修专业队1支270人、消防专业队1支122人、治安专业队1支120人、伪装防护专业队1支140人，*****组建了重要目标抢险抢修专业队1支240人、防化防疫专业队1支30人、治安专业队1支80人、伪装防护专业队1支80人，*****组建了重要目标抢险抢修专业队1支220人、治安专业队1支60人、伪装防护专业队1支80人；*****建了信息防护专业队60人。`);
const toolbarConfig11 = {};
const editorConfig11 = { placeholder: "请输入内容..." };
const mode11 = ref("default");
const handleCreated11 = (editor) => {
  editorRef11.value = editor; // 记录 editor 实例，重要！
};
// 表头单元格样式
const headerCellStyle = () => {
  return {
    backgroundColor: "#f5f7fa",
    color: "rgba(0,0,0,0.85)",
    fontSize: "14px",
    height: "54px",
  };
};
// 单元格样式
const cellStyle = () => {
  return {
    color: "rgba(0,0,0,0.65)",
    fontSize: "14px",
    lineHeight: "22px",
  };
};

const tableData = ref([]);

// 重要目标单位专业队任务需求清单
const xqList = ref([]);
const getXqData = () => {
  return postTableData({
    docType: "targetProtection",
    method: "zhongyaomubiaodanweizhuanyeduirenwu",
  }).then((res) => {
    if (res.code === 200) {
      xqList.value = res?.data || [];
    }
  });
};

// 重要目标单位专业队建设情况统计表
const jsList = ref([]);
const geJsData = () => {
  return postTableData({
    docType: "targetProtection",
    method: "zhongyaomubiaodanweizhuanyeduijiansheqingkuang",
  }).then((res) => {
    if (res.code === 200) {
      jsList.value = res?.data || [];
    }
  });
};
// 加载html
const initHtml = () => {
  searchDataZymb({ m: "任务需求防护专业力量建设任务需求和能力现状" }).then(
    (res) => {
      const { data } = res;
      valueHtml11.value = data.find((x) => x.k === "防护任务需求")?.v || "";
    }
  );
};
const saveProgramme = () => {
  ElMessageBox.confirm(`确定要保存吗?`, "警告", {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    type: "warning",
    customClass: "message-box",
  }).then(() => {
    addOrUpdateZymb({
      m: "任务需求防护专业力量建设任务需求和能力现状",
      data: [
        {
          k: "防护任务需求",
          v: valueHtml11.value,
        },
      ],
    })
      .then(() => {
        ElMessage.success("操作成功");
      })
      .catch(() => {});
  });
};
onMounted(() => {
  initHtml();
});
onBeforeUnmount(() => {
  if (editorRef11.value) editorRef11.value.destroy();
});
</script>
<template>
  <div>
    <FirstTitle name="任务需求" class="top-15" />

    <div style="border: 1px solid #ccc" class="top-15">
      <Toolbar
        style="border-bottom: 1px solid #ccc"
        :editor="editorRef11"
        :defaultConfig="toolbarConfig11"
        :mode="mode11"
      />
      <Editor
        style="height: 500px; overflow-y: hidden"
        v-model="valueHtml11"
        :defaultConfig="editorConfig11"
        :mode="mode11"
        @onCreated="handleCreated11"
      />
    </div>

    <div class="flex-justify-end top-20">
      <el-button type="primary" class="save-btn" @click="saveProgramme"
        >保存</el-button
      >
    </div>
  </div>
</template>
<style scoped lang="scss"></style>